package com.zhongwang.business.module.estimateBudgetAccountingManage.controller;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zhongwang.business.base.BaseController;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.gen.entity.BusBudgetAccountingBasicInfoConfigTemplate;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMachiningEquipmentModel;
import com.zhongwang.business.module.estimateBudgetAccountingManage.service.BasicInfoConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 徐一贺
 * @className BasicInfoConfigController
 * @description 概算预算核算基础信息配置控制层
 * @date 2020/11/27 10:10
 * @versron ver 1.0
 */
@Controller
@RequestMapping("/basicInfoConfig")
public class BasicInfoConfigController extends BaseController {

    @Autowired
    private BasicInfoConfigService service;

    /**  basicConfig 跳转到概算预算核算基础信息配置页面
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/11/27 10:13
     */
    @GetMapping("/basicConfig")
    @RequiresPermissions("basic:estbudacc:view")
    public String basicConfig(){
        return "basicManage/basicInfoConfig/page";
    }

    /**  macQuotaConfig 跳转到机加定额配置页面
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/11/27 10:13
     */
    @GetMapping("/macQuotaConfig")
    @RequiresPermissions("basic:macquota:view")
    public String macQuotaConfig(){
        return "basicManage/macQuotaConfig/page";
    }

    /**  basicConfigList 获取概算预算核算基础信息配置列表
     * @param param 检索参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/27 10:29
     */
    @ResponseBody
    @PostMapping("/basicConfig/list")
    @RequiresPermissions("basic:estbudacc:view")
    public JsonResult basicConfigList(BusBudgetAccountingBasicInfoConfigTemplate param){
        startPage();
        return jsonResult(service.basicConfigList(param));
    }

    /**  macQuotaConfigList 获取机加定额列表
     * @param param 检索参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/27 11:16
     */
    @ResponseBody
    @PostMapping("/macQuotaConfig/list")
    @RequiresPermissions("basic:macquota:view")
    public JsonResult macQuotaConfigList(BusMachiningEquipmentModel param){
        startPage();
        return jsonResult(service.macQuotaConfigList(param));
    }
    /**  versionList 获取机加定额版本列表
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/27 11:16
     */
    @ResponseBody
    @PostMapping("/macQuotaConfig/versionList")
    @RequiresPermissions("basic:macquota:view")
    public JsonResult versionList(){
        startPage();
        return jsonResult(service.versionList());
    }

    /**  loadSearchConditionData 获取机加定额基础信息检索条件数据
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/27 12:48
     */
    @ResponseBody
    @PostMapping("/macQuotaConfig/loadSearchConditionData")
    @RequiresPermissions("basic:macquota:view")
    public JsonResult loadSearchConditionData(){
        return success().setData(service.loadSearchConditionData());
    }

    /**  createMacQuotaConfigList 创建新版本积机加数据
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @exception
     * @author 徐一贺
     * @date 2020/11/27 17:53
     */
    @ResponseBody
    @PostMapping("/macQuotaConfig/createMacQuotaConfigList")
    @RequiresPermissions("basic:macquota:view")
    public JsonResult createMacQuotaConfigList(String version,Integer isDefault,String machiningData){
        Gson gson = new Gson();
        List<BusMachiningEquipmentModel> machiningDataList = gson.fromJson(machiningData, new TypeToken<List<BusMachiningEquipmentModel>>(){}.getType());
        return service.createMacQuotaConfigList(version,isDefault,machiningDataList);
    }

    /**  basicConfigUpdateValue 更新基础信息
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/27 10:48
     */
    @ResponseBody
    @PostMapping("/basicConfig/updateValue")
    @RequiresPermissions("basic:estbudacc:view")
    public JsonResult basicConfigUpdateValue(BusBudgetAccountingBasicInfoConfigTemplate param){
        return service.basicConfigUpdateValue(param);
    }
    /**  basicConfigSetDefault 设置为此版本号为系统默认
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/27 10:48
     */
    @ResponseBody
    @PostMapping("/macQuotaConfig/setDefault")
    @RequiresPermissions("basic:estbudacc:view")
    public JsonResult basicConfigSetDefault(BusBudgetAccountingBasicInfoConfigTemplate param){
        return service.basicConfigSetDefault(param);
    }

    /**  basicConfigUpdatePrice 修改定额
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/27 10:48
     */
    @ResponseBody
    @PostMapping("/macQuotaConfig/updatePrice")
    @RequiresPermissions("basic:estbudacc:view")
    public JsonResult basicConfigUpdatePrice(BusMachiningEquipmentModel param){
        return service.basicConfigUpdatePrice(param);
    }

    /**  getNewMachiningQuotaConfigList 获取创建定时需要的数据
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/27 10:48
     */
    @ResponseBody
    @PostMapping("/macQuotaConfig/getNewMachiningQuotaConfigList")
    @RequiresPermissions("basic:estbudacc:view")
    public JsonResult getNewMachiningQuotaConfigList(){
        return jsonResult(service.getNewMachiningQuotaConfigList());
    }

    /**  macQuotaConfigCheckExist 检测机加版本号是否存在
     * @param version 版本号
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/30 7:52
     */
    @ResponseBody
    @PostMapping("/macQuotaConfig/checkExist")
    @RequiresPermissions("basic:estbudacc:view")
    public JsonResult macQuotaConfigCheckExist(String version){
        return service.macQuotaConfigCheckExist(version);
    }

    /**  basicConfigGetMacVersionList 获取版本列表
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/1 20:10
     */
    @ResponseBody
    @PostMapping("/basicConfig/getMacVersionList")
    @RequiresPermissions("basic:estbudacc:view")
    public JsonResult basicConfigGetMacVersionList(){
        return jsonResult(service.basicConfigGetMacVersionList());
    }

}
